/*
 This file 'App.Project' is part of Firebird Integrated Solution 1.0

 Copyright (c) 2018 Lincong

 Contact:  
        Email: lincong1987@gmail.com

        QQ: 159257119
 
 See Usage at http://www.jplatformx.com/firebird

 Create date: 2018-07-27 15:29
 */

define(function (require, exports, module) {

	require("Firebird.AppFramework");

	Firebird.SearchApp.override({
		handlers: {
			query: function (e) {
				e.data.context.J_grid.query();
			},
			save: function (e) {
				var app = this;
				app.controller.save({app: this, context: this.context, title: "新增", lock: true}, function (operation) {
					if (operation.success) {
						Firebird.ui.Dialog.tips("数据新增成功！", 5000);
						app.context.J_grid.reload();
					}
				});
			},
			edit: function (e) {
				var app = this;
				//var ids = app.context.J_grid.getCheckedRowIds();
				app.setActionIds(e);
				var ids = app.getActionIds(e);
				if (ids.length != 1) {
					Firebird.ui.Dialog.warn("请选择一条数据进行操作！");
					return;
				}
				app.controller.edit(ids[0], {app: app, context: app.context, title: "修改"}, function (operation) {
					if (operation.success) {
						Firebird.ui.Dialog.tips("数据修改成功！", 5000);
						app.context.J_grid.reload();
					}
				});
			},
			view: function (e) {
				var app = this;
				app.setActionIds(e);
				var ids = app.getActionIds(e);
				if (ids.length != 1) {
					Firebird.ui.Dialog.warn("请选择一条数据进行查看！");
					return;
				}
				app.controller.view(ids[0], {app: app, context: app.context, title: "查看"}, function (operation) {
					if (operation.success) {
					}
				});
			},
			"delete": function (e) {
				var app = this;
				app.setActionIds(e);
				var ids = app.getActionIds(e);
				if (ids.length == 0) {
					Firebird.ui.Dialog.warn("请选择一条或多条数据进行操作。");
					return;
				}
				Firebird.ui.Dialog.confirm("数据即将被删除，请确认后操作。<br><br>点击【取消】，数据不会删除，点击【确认】，删除数据。", function () {
					app.controller.remove(ids, {app: app, context: app.context}, function (operation) {
						if (operation.success) {
							Firebird.ui.Dialog.tips("数据已删除！", 5000);
							app.context.J_grid.reload();
						}
					});
				});
			},
			"reset": function (e) {
				this.context.J_form.clear();
			}
		}
	});


	module.exports = Firebird.App;
});